import Vue from 'vue'
import Router from 'vue-router'
import HelloWorld from '@/components/HelloWorld'

import login from '../components/login';
import register from '../components/register';
import forgetpassword from '../components/forgetpassword';
import productList from '../components/productList';
import cusTomer from '../components/cusTomer';
import perSon from '../components/perSon';
import customDetial from '../components/customDetial';
import goShare from '../components/goShare';
import goShareios from '../components/goShareios';
import tixian from '../components/tixian';
import changePassword from '../components/changePassword';
import message from '../components/message';
import msgDetial from '../components/msgDetial';
import member from '../components/member';
import mer_pay from '../components/mer_pay';

import shareDaikuan from '../components/shareDaikuan';
import shareXinyongka from '../components/shareXinyongka';
import xieyi from '../components/xieyi';
import paystatus from '../components/paystatus';
import download from '../components/download';
Vue.use(Router)

let router = new Router({
    mode: 'history',
    routes: [
        {path: '/', component: productList, meta: {title: '微金网',auth:false}},
        // {path: '/', component: login, meta: {title: '微金网-合伙人登录',auth:false}},
        {path: '/login', component: login, meta: {title: '微金网-合伙人登录',auth:false}},
        {path: '/register', component: register, meta: {title: '微金网-合伙人注册',auth:false}},
        {path: '/forgetpassword', component: forgetpassword, meta: {title: '微金网-密码找回',auth:false}},
        {path: '/productList', component: productList, meta: {title: '微金网-推广赚钱',auth:false}},
        {path: '/cusTomer', component: cusTomer, meta: {title: '微金网-我的客户',auth:true}},
        {path: '/perSon', component: perSon, meta: {title: '微金网-个人中心',auth:true}},
        {path: '/customDetial', component: customDetial, meta: {title: '微金网-产品详情',auth:false}},
        {path: '/goShare', component: goShare, meta: {title: '微金网-我的推广',auth:true}},
        {path: '/goShareios', component: goShareios, meta: {title: '微金网-我的推广',auth:false}},
        {path: '/tixian', component: tixian, meta: {title: '微金网-提现',auth:true}},
        {path: '/changePassword', component: changePassword, meta: {title: '微金网-修改密码',auth:true}},
        {path: '/message', component: message, meta: {title: '微金网-我的消息',auth:true}},
        {path: '/msgDetial', component: msgDetial, meta: {title: '微金网-消息详情',auth:true}},
        {path: '/member', component: member, meta: {title: '微金网-会员介绍',auth:true}},
        {path: '/mer_pay', component: mer_pay, meta: {title: '微金网-会员支付',auth:true}},
        {path: '/shareDaikuan', component: shareDaikuan, meta: {title: '微金网-贷款推广',auth:true}},
        {path: '/shareXinyongka', component: shareXinyongka, meta: {title: '微金网-信用卡推广',auth:true}},
        {path: '/xieyi', component: xieyi, meta: {title: '微金网-用户协议',auth:false}},
        {path: '/paystatus', component: paystatus, meta: {title: '微金网-用户协议',auth:false}},
        {path: '/download', component: download, meta: {title: '微金网-app下载',auth:false}},
    ]
})

Router.prototype.go = function (a) {
    sessionStorage.isBack = true
    if (a) {
        window.history.go(a)
    } else {
        window.history.go(-1)
    }
    console.log(a)
}


window.addEventListener("popstate", function (e) {
    sessionStorage.isBack = true
}, false);


router.beforeEach((to, from, next) => { //to:即将前往的页面,from:从哪个页面来,next:下一步操作
    if(to.matched.some(res => res.meta.auth)){
        console.log("需要登录后查看");
        if(localStorage.hhrdata){
            next();
        }else{
            next({path: '/login'})
        }
    }else{
        next();
    }
})

export default router;
